package top.mataiji.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.mataiji.manager.mapper.User_moneyMapper;
import top.mataiji.manager.pojo.User_money;
import top.mataiji.manager.pojo.User_moneyExample;
import top.mataiji.manager.service.User_moneyServer;

import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2021/4/16 - 04 - 16 - 10:45
 * @Description: top.mataiji.manager.service.impl
 * @version: 1.0
 */
@Service
public class User_moneyServerImpl implements User_moneyServer {

    @Autowired
    User_moneyMapper user_moneyMapper;

    @Override
    public Long selectMoneyByUserId(Integer userid) {
        //创建查询对象
        User_moneyExample user_moneyExample = new User_moneyExample();
        user_moneyExample.createCriteria().andUserIdEqualTo(userid);
        List<User_money> user_monies = user_moneyMapper.selectByExample(user_moneyExample);
        if(!user_monies.isEmpty()&&user_monies!=null){
            return user_monies.get(0).getUserBalance();
        }
        return null;
    }

    @Transactional
    @Override
    public Integer pay(Long orderPrice, Integer userId) {
        return user_moneyMapper.updateByUserid(userId,orderPrice);
    }
}
